package com.yifan.clone;


import java.io.IOException;
import com.yifan.clone.*;
import org.springframework.beans.BeanUtils;

/**
 * @Author YIFan
 * @Date 2020/7/15 14:20
 * @Version 1.0
 */
public class Tset {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Person person = new Person(15,"jack");
        Arm arm = new Arm();
        arm.setArmName("qweqr");
        person.setArm(arm);

        // 深克隆
        Person clone1 = (Person)person.deepClone();
        System.err.println("深克隆修改前------");
        System.err.println("clone --> "+clone1.getArm().getArmName());
        System.err.println("person --> "+person.getArm().getArmName());
        System.err.println(clone1.getName());

        System.err.println("深克隆修改后------");
        clone1.getArm().setArmName("小米");
        clone1.setName("lucy");
        System.err.println("clone --> "+clone1.getArm().getArmName());
        System.err.println("person --> "+person.getArm().getArmName());
        System.err.println(clone1.getName());

        System.out.println("-----------------------");

        // 浅克隆
        Person clone = new Person(15,"jack");
        BeanUtils.copyProperties(person,clone);

        System.err.println("浅克隆修改前------");
        System.err.println("clone --> "+clone.getArm().getArmName());
        System.err.println("person --> "+person.getArm().getArmName());
        System.err.println(clone.getName());

        System.err.println("浅克隆修改后------");
        clone.getArm().setArmName("小米");
        clone.setName("lucy");
        System.err.println("clone --> "+clone.getArm().getArmName());
        System.err.println("person --> "+person.getArm().getArmName());
        System.err.println(clone.getName());


    }
}
